package org.windey.server.web;

import org.windey.server.database.User;

public class Sidebar {
	
	private User user;
	
	public Sidebar(User u) {
		if (u == null) {
			setUser(null);
		}
		else {
			setUser(u);
		}
	}
	
	public void setUser(User user) {
		this.user = user;
	}
	public User getUser() {
		return user;
	}
	
	public String generate() {
		String s = "<div id=\"sidebar\">" + 
					"<div id=\"sidebar-bgtop\">" + 
					"<div id=\"sidebar-bgbtm\">" +
					"<ul>" + 
					"<li>";
		if (getUser() == null) {
			s += "<h2>Log In</h2>" + 
					"<div id=\"search\">" + 
					"<form action=\"processlogin.jsp\" method=\"post\">" + 
					"<table>" + 
					"<tr>" + 
					"<td><input name=\"email\" type=\"text\" /></td>" + 
					"</tr>" + 
					"<tr>" + 
					"<td><input name=\"pass\" type=\"password\" /></td>" + 
					"</tr>" + 
					"<tr>" + 
					"<td><input name=\"login\" type=\"submit\" value=\"Log In\" /></td>" + 
					"</tr>" + 
					"</table>" + 
					"</form>" + 
					"</div>";
		}
		else {
			s += "<h2><a href=\"logout.jsp\">Log Out</a></h2>" + 
					"<div id=\"search\">" + 
					"<p><em>Logged in as " + user.getEmail() + "</em></p>" + 
					"<p><a href=\"overview.jsp\">Overview of PC's</a></p>" + 
					"</div>";
		}
		s += "<div style=\"clear: both;\">&nbsp;</div>" + 
				"</li>" + 
				"</ul>" + 
				"</div>" + 
				"</div>" + 
				"</div>";
		return s;
	}


}
